package studentmanage.controller;

import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;
import studentmanage.entity.Students;
import studentmanage.service.StudentService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import studentmanage.tools.result.Result;

import java.util.List;

@Api(tags = "学生相关接口")
@RestController
@Slf4j
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping("/select")
    @ApiOperation("查看所有学生")
    public Result<List<Students>> selectAllStudent(){
        List<Students> list =studentService.selectAllStudent();
        return Result.success(list);
    }

    @PostMapping("/add")
    @ApiOperation("添加学生信息")
    public Result<String> addStudent(@RequestBody Students students){
        studentService.addStudent(students);
        return Result.success("添加成功");
    }
    @DeleteMapping("/delete/{studentId}")
    @ApiOperation("删除学生")
    public Result<String> deleteStudent(@PathVariable long studentId){
        studentService.deleteStudent(studentId);
        return Result.success("删除成功");
    }
    @PostMapping("/update")
    @ApiOperation("修改学生信息")
    public Result<String> updateStudent(@RequestBody Students students){
        studentService.updateStudent(students);
        return Result.success("修改成功");
    }

}
